package sol.leetcode;

import java.util.*;

/**
 * Summary Ranges
 */
public class Issue228 {
    public List<String> summaryRanges(int[] nums) {
        List<String> res = new ArrayList<String>();

        for (int i = 0, j = 1; j <= nums.length; ++j) {
            if (j == nums.length || nums[j] > nums[j - 1] + 1) {
                if (i == j - 1)
                    res.add("" + nums[i]);
                else
                    res.add(nums[i] + "->" + nums[j - 1]);
                i = j;
            }
        }

        return res;
    }

    public static void main(String[] args) {
        int[] nums = {0, 1, 2, 4, 5, 7};
        List<String> res = new Issue228().summaryRanges(nums);
        System.out.println(res);
    }

}
